﻿Imports System.Linq
Imports TNCDAL

Public Class ConfigController
    Private objRepository As New ConfigRepository

    Public Function SelectAllRecord() As IQueryable(Of tblConfig)
        Return objRepository.SelectAllRecord()
    End Function

    Public Function SelectRecordById(ByVal id As Integer) As tblConfig
        Return objRepository.SelectRecordById(id)
    End Function

    Public Sub Insert(ByVal obj As tblConfig)
        objRepository.Insert(obj)
    End Sub

    Public Sub Update(ByVal obj As tblConfig)
        objRepository.Update(obj)
    End Sub

    Public Function SelectCustom(ByVal strName As String, ByVal value As String, ByVal strDes As String) As IQueryable
        Dim query = SelectAllRecord()

        If strName <> "" Then
            query = query.Where(Function(p) p.ConfigName.ToLower.Contains(strName.ToLower))
        End If

        If value <> "" Then
            query = query.Where(Function(p) p.Value.ToLower.Contains(value.ToLower))
        End If

        If strDes <> "" Then
            query = query.Where(Function(p) p.Description.ToLower.Contains(strDes.ToLower))
        End If

        'query = query.OrderBy(Function(p) p.DemDetName)
        Return query
    End Function
End Class
